/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uk.co.dupenois.geometry.combinatorialmap;

import uk.co.dupenois.geometry.Coordinate;
import uk.co.dupenois.geometry.Edge;

/**
 *
 * @author Max
 */
public class Dart {
    //Next dart around the start vertex in a positive direction
    private Dart sigma;

    //Opposite of this dart
    private Dart alpha;

    //Used to create it so kept to make
    //angle rotations clearer
    private Edge edge;

    private Coordinate start;
    private Coordinate end;

    public Dart(Coordinate start, Coordinate end, Edge edge){
        this.start = start;
        this.end = end;
        this.edge = edge;
    }

    /**
     * Sigma is the next dart around the start vertex in a positive direction
     * (anti-clokwise)
     * @return the sigma
     */
    public Dart getSigma() {
        return sigma;
    }

    /**
     * Sigma is the next dart around the start vertex in a positive direction
     * (anti-clokwise)
     * @param sigma the sigma to set
     */
    public void setSigma(Dart sigma) {
        this.sigma = sigma;
    }

    /**
     * The dart corresponding to this edge heading in the
     * opposite direction
     * @return the alpha
     */
    public Dart getAlpha() {
        return alpha;
    }

    /**
     * The dart corresponding to this edge heading in the
     * opposite direction
     * @param alpha the alpha to set
     */
    public void setAlpha(Dart alpha) {
        this.alpha = alpha;
    }

    /**
     * The start coordinate of this dart
     * @return the start
     */
    public Coordinate getStart() {
        return start;
    }

    /**
     * The end coordinate of this dart
     * @return the end
     */
    public Coordinate getEnd() {
        return end;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 47 * hash + (this.start != null ? this.start.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object other){
        if(other == this) return true;
        if(!(other instanceof Dart)) return false;
        Dart oDart = (Dart)other;
        return (oDart.getStart().equals(this.getStart())&&
                oDart.getEnd().equals(this.getEnd()));
    }

    public Dart function(String functionStr){
        char[] charArr = functionStr.toCharArray();
        Dart dart = this;
        for(char c : charArr){
            if(c=='a') {
                dart = dart.getAlpha();
            }else if(c=='s'){
                dart = dart.getSigma();
            }
        }
        return dart;
    }

    /**
     * The line is taken in at instantiation so kept to make
     * angle rotations easier
     * @return the edge
     */
    public Edge getEdge() {
        return edge;
    }

    @Override
    public String toString(){
        return this.getStart()+"->"+this.getEnd();
    }

}
